// 监听来自popup的消息
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    if (message.action === "openSidepanel") {
      // 获取当前活动标签页
      chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
        if (tabs[0]) {
          // 设置侧边栏选项
          chrome.sidePanel.setOptions({
            tabId: tabs[0].id,
            path: "view/sidepanel/index.html",
            enabled: true,
          });
          // 打开侧边栏
          chrome.sidePanel.open({ tabId: tabs[0].id });
        }
      });
    }
  });
  
  // 点击扩展图标时的处理
  chrome.action.onClicked.addListener((tab) => {
    chrome.sidePanel.setOptions({
      tabId: tab.id,
      path: "view/sidepanel/index.html",
      enabled: true,
    });
    chrome.sidePanel.open({ tabId: tab.id });
  });